﻿package com.dingpeikeji.quickdeer.modules.wx.wxshare.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dingpeikeji.quickdeer.modules.wx.wxshare.util.Sign;
import com.dingpeikeji.quickdeer.modules.wx.wxshare.util.TickFile;
import com.tencent.common.Configure;

import net.sf.json.JSONObject;

public class CrazyServlet extends HttpServlet {
	
	
	public static String APPID = Configure.getAppid();//appid 改为自己的appid
	public static String APPSECRET = Configure.getAppsecret();//红色
	// 凭证获取（GET）
	public final static String token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+APPID+"&secret="+APPSECRET;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url = request.getParameter("url");
		Map<String, String> params;
		try {
			params = Sign.sign(TickFile.getTicke(),url);
			System.out.println("sign----------  "+url);
			JSONObject jsonObject = JSONObject.fromObject(params);
			jsonObject.put("appid", APPID);
			String jsonStr = jsonObject.toString();
			System.out.println("jsonStr"+jsonStr);
			PrintWriter out = response.getWriter();
			out.write(jsonStr);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);
	}

}
